<?php
class Response
{
    // json 方式 输出通信数据
    public static function json($code, $msg = '', $data = [])
    {
        if(!is_numeric(($code))){
            return false;
        }
        echo urldecode(json_encode([
            'code' => $code,
            'msg' => urlencode($msg),
            'data' => $data
        ]));

        exit;
    }

    const JSON = "json";
    public static function show($code, $message = '', $data = array())
    {
        if (!is_numeric($code)) {
            return '';
        }

        $type = isset($_GET['format']) ? $_GET['format'] : self::JSON;

        $result  = array(
            'code' => $code,
            'message' => $message,
            'data' => $data
        );

        if ($type == 'json') {
            self::json($code, $message, $data);
            exit;
        } elseif ($type == 'array') {
            var_dump($result);
        }
    }
}
